<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>高德地图 - 只显示河北</title>
    <script src="https://webapi.amap.com/maps?v=2.0&key=761ca7e04038e3c16aaf3cea353c6373"></script>
    <style>
        html, body, #container { width: 100%; height: 100%; margin: 0; }
    </style>
</head>
<body>
<div id="container"></div>
<script>
    var map = new AMap.Map("container", {
        center: [115.502461, 38.045474], // 河北省中心坐标
        zoom: 7, // 适合河北的缩放级别
        viewMode: '2D', // 2D 视图
        mapStyle: 'amap://styles/dark' // 地图样式（可选）
    });

    AMap.plugin('AMap.DistrictSearch', function () {
        var district = new AMap.DistrictSearch({
            level: 'province',
            extensions: 'all'
        });

        district.search('河北省', function (status, result) {
            if (status === 'complete' && result.districtList.length) {
                var boundaries = result.districtList[0].boundaries;

                if (!boundaries) return;

                // 定义一个超大矩形（全球范围）
                var outer = [
                    [0, 90], [180, 90], [180, -90], [0, -90], [-180, -90], [-180, 90], [0, 90]
                ];

                // 创建遮罩层（河北省以外的部分全部黑色）
                var mask = new AMap.Polygon({
                    path: [outer].concat(boundaries), // 镂空河北省
                    fillColor: "#000", // 黑色背景
                    fillOpacity: 0.9, // 透明度
                    strokeColor: "rgba(0,0,0,0)", // 隐藏边界线
                    strokeOpacity: 0
                });

                map.add(mask);

                // 河北省轮廓高亮
                var hebeiPolygon = new AMap.Polygon({
                    path: boundaries,
                    fillColor: "#00AAFF", // 河北省高亮颜色
                    fillOpacity: 0.6, // 透明度
                    strokeColor: "#00FFFF", // 边界线颜色
                    strokeWeight: 2
                });

                map.add(hebeiPolygon);

                // 调整视野适应河北省范围
                map.setBounds(hebeiPolygon.getBounds());
            }
        });
    });
</script>
</body>
</html>
